<?php
/*
 * @Author: your name
 * @Date: 2021-11-03 15:16:15
 * @LastEditTime: 2021-12-20 09:27:41
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \property\app\Models\admin_model\Column.php
 */

namespace App\Models\admin_model;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

class FreeDistribution extends Model
{
    use HasFactory;
    public static string $tableName = 'free_distribution';

    public static function list($whereStr = '', $limitStr = '', $field='*')
    {
        return DB::select(' SELECT `free_distribution`.*,`find_shop_user`.`nickName`,`find_shop_user`.`avatarUrl`,`find_shop_user`.`source`  FROM ' . self::$tableName . ' LEFT JOIN `find_shop_user` ON `free_distribution`.`user_openid` = `find_shop_user`.`openid`   WHERE  `free_distribution`.`delete_time` is null ' . $whereStr . ' ORDER BY `free_distribution`.`top_time` DESC ,`free_distribution`.`id` DESC  ' . $limitStr);
    }
    
    public static function count($whereStr = '')
    {
        return DB::select(' SELECT COUNT(*) as `count` FROM ' . self::$tableName . ' LEFT JOIN `find_shop_user` ON `free_distribution`.`user_openid` = `find_shop_user`.`openid`    WHERE  `free_distribution`.`delete_time` is null ' . $whereStr);
    }

    public static function releasePlan($openid ){
        return DB::select( 'SELECT * FROM '.self::$tableName.' WHERE `user_openid` = "'.$openid.'" ORDER BY `id` DESC' );

    }
    
}